﻿using System;
using System.Web.UI;
using Cms.Application.Admin.Presenters;
using Cms.Application.Admin.Views;
using Cms.Domain.Authentication;

namespace Cms.Web.UI.Admin
{
    public partial class UploadCheck : Page, IUploadCheckView
    {
        private UploadCheckPresenter _presenter;

        #region IUploadCheckView Members

        public void SetExistingFiles(string files)
        {
            if (files != "")
                Page.ClientScript.RegisterStartupScript(GetType(), "validate",
                                                        "parent.displayOverwriteConfirmation('" + files + "');", true);
            else
                Page.ClientScript.RegisterStartupScript(GetType(), "upload", "parent.validationCallback('ok');", true);
        }


        public int AdministratorID
        {
            get
            {
                try
                {
                    if (User.Identity.Name != "")
                    {
                        AuthenticatedUser user = Conversion.ToAuthenticatedUser(User.Identity.Name);
                        return user.AdministratorID;
                    }
                }
                catch
                {
                }
                return -1;
            }
        }

        #endregion

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _presenter = new UploadCheckPresenter(this);
        }


        protected void lbCheck_Click(object sender, EventArgs e)
        {
            _presenter.CheckFiles(hidSelectedFiles.Value);
        }
    }
}